<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Pragma" content="no-cache" />
		<title>通讯录</title>
		<%@ include file="/user_comm.jsp"%>
		<!--  
<link rel="stylesheet"	href="http://a.tbcdn.cn/apps/sell/1.0/publish_detail_ke.css?t=20110128editor.css" />
 -->
		<!-- script start -->
		<script language="JavaScript">
	var selGroupId=0; //当前所选联系组ID
	var selMemberId='';//当前所选联系人ID
	var contactList; //所有联系人数据
	$(document).ready(function(){
		loadContact();
		loadMember(0);//显示所有
	});
	
	function loadContact(){
		var params = {};
		$.ajax({type: "POST",
		       url: "ajaxContact_loadContact.do",
		       data: params,
		       async: false,   
		       success: function(result){
				contactList = result.contactList;
				var groupHtml="";
				for(var i=0;i<contactList.length;i++){
					var group=contactList[i].group;
					groupHtml +="<a href='#' onclick=\"loadMember("+group.id+");\">"+group.groupName+"("+group.count+")</a><br/>";
				}
				$("#spanGroups").html(groupHtml);
			  }
			},"json");
	}
	
	//通过组ID取组成员信息
	function getGroupMembers(groupId){
		for(var i=0;i<contactList.length;i++){
			var group=contactList[i].group;
			if(group.id==groupId){
				return contactList[i].memberList;
			}
		}
		return;
	}
	
	//加载联系人列表
	function loadMember(groupId) {
	    selMemberId='';
   	    selGroupId=groupId;
		var memberList = getGroupMembers(groupId);
		if(memberList.length==0){   
		    $("#tb_memberList").html("<tr><td><span class='orange1 ml5'>没有联系人在分组中</span></td></tr>");
		    return;
		}
				
		var result="<thead>"
		result += "<tr>";
		result += "<th class='title' align='center'></th>";
		result += "<th class='title'>账户代码</th>";
		result += "<th class='title'>账户名称</th>";
		result += "<th class='title'>姓名</th>";
		result += "<th class='title'>电话</th>";
		result += "<th class='title'>电子邮件</th>";
		result += "</tr>";
		result += "</thead>";
		result += "<tbody>";
		//这里的order[i]就相当于list中的order,起属性也是一一对应的   
		for(var j=0;j<memberList.length;j++) {   
		    result += "<tr>"; 
		    result += "<td align='center' width='20'><input id='"+memberList[j].id+"' name='chkSon' type='checkbox' value='"+memberList[j].id+"'></td>";
		    result += "<td>"+memberList[j].relateUserid+"</td>";   
		    result += "<td>"+memberList[j].relateCompanyName+"</td>";
		    result += "<td>"+memberList[j].relateName+"</td>";
		    result += "<td>"+memberList[j].telephone+"</td>";
		    result += "<td>"+memberList[j].email+"</td>";
		    result += "</tr>";   
		} 
		result += "</tbody>";
		$("#tb_memberList").html(result);
	}
	
</script>
		<!-- script end -->
	</head>
	<body>
		<div class="con Orbuy">
			<form name="formpage">
				<div class="pCenter">
					<div>
						<table>
							<tr>
								<td width="200" valign="top">
									<div style="border: 1px solid #c5ddf6; padding: 5px;">
										<span id="spanGroups"> </span>
									</div>
								</td>
								<td width="650" valign="top">
									<!-- 联系人列表 start -->
									<div id="div_memberlist" style="display: block;">
										<table class="favorRwList mt5" id="tb_memberList">
										</table>
									</div>
									<!-- 联系人列表 end -->
								</td>
							</tr>
							<tr>
								<td align="center" colspan="2">
									<br/>
									<p class="formAction">
										<input type="button" class="button" id="ok" name="ok"
											value=" 确认 " onclick="saveGroup();" />
										&nbsp;&nbsp;&nbsp;&nbsp;
										<input type="button" class="button" id="resets" value=" 返回 "
											onclick="goBack();" />
									</p>
								</td>
							</tr>
						</table>
					</div>
				</div>
			</form>
		</div>
	</body>
</html>
